<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/9
 * Time: 10:21
 */
$username = $_POST['username'];
$pwd = $_POST['pwd'];
$userkey ='';

$mag='';
$url='';

//$conn = new mysqli('127.0.0.1','root','123456','newmy');

$conn = new mysqli();
$conn->connect('127.0.0.1','root','123456','newmy');
//connect_error错误信息提示
if(!empty($conn->connect_error)){//如果错误信息不为空，有错误
    echo 'MYSQL数据库连接错误: '.$conn->connect_error;
    die;
}
$result = $conn->query('select a.RealName,b.CardNo,b.CardPwd from accountinfo a LEFT JOIN bankcard b ON a.AccountId=b.AccountId');
while (true){
    $row = $result->fetch_array();
    if (empty($row)){
        $mag='密码或用户名错误！！！';
        $url='../index.php';
        break;
    }
    if ($username==$row['CardNo']&&$pwd==$row['CardPwd']) {
        session_start();
        $username = $row['RealName'];
        $userkey=md5($username.$pwd);
        setcookie('userkey',$userkey,time()+24*3600,'/');
        $_SESSION[$userkey]=[
           'username'=>$username,
           'userkey'=>$userkey
        ];
        $mag='登录成功，正在进入用户中心！！！';
        $url='userinfo.php';
        break;
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
<input type="hidden" id="url" value="<?php echo $url ?>"/>
<input type="hidden" id="masg" value="<?php echo $mag ?>"/>
</body>
<script type="text/javascript">
    onload= function(){
        var mag = document.getElementById('masg').value;
        var url = document.getElementById('url').value;
        alert(mag);
        location.href=url;
    }
</script>
</html>
